{php include wl_template('common/header');}

<ul class="nav nav-tabs">

	

	<li {if $op=='display'}class="active"{/if}><a href="{php echo web_url('member/smsbuy', array('op' => 'display'))}"><i class="icon-group"></i> 年度VIP</a></li>
	</ul>
{if $op=='display'}
<div class="panel panel-default">

		

		<div class="panel-body">
 <form  method="get" class="form-horizontal" role="form" id="form1">               
               
			<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">年度VIP</label>

					<div class="col-sm-10">

						<label class="radio-inline"><input type="radio" value="8168" name="smsnum" >5999/年</label>	
						<label class="radio-inline"><input type="radio" value="8191" name="smsnum" >7999/年(至尊版,可自定义域名)</label>	
					</div>

				</div>
				
				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">扫码支付</label>

					<div class="col-sm-10">

						<label class="radio-inline"><img  src="{TG_URL_WRES}images/paylogo.png" width="150px" height="150px" id="payimage"></label>
						
					</div>

				</div>
				<div class="form-group">

					
					<div class="col-sm-10">

						<label class="radio-inline" style="margin-left:80px;"><img  src="{TG_URL_WRES}images/function/vip.jpg"   id="payimage"></label>
						
					</div>

				</div>
			</form>	
				
				
</div>
</div>


<script>
$(function(){ 
$('input:radio[name="smsnum"]').change(function() { 
var smsnum=$("input[name='smsnum']:checked").val();
var orderno=RandomS();
	var data=new FormData();
						data.append('id',smsnum);						
						data.append('num',1);
						data.append('orderno',orderno);	
						data.append('uniacid',33);	
						var url="{php echo web_url('store/setting/qr');}";
						var xhr=new XMLHttpRequest();
						xhr.onreadystatechange=function(){
							if (xhr.readyState==4){
								if ((xhr.status>=200 && xhr.status<300)|| xhr.status==304){
									

									document.getElementById("payimage").src="{TG_URL}"+"data/qrcode/33/"+orderno+".png";
									var intervalId = setInterval("startRequest1('"+orderno+"')",1000); 
									//clearInterval(intervalId);
								}
							}
						}
						xhr.open("post",url,true);
						xhr.send(data);	
}); 
}); 

function startRequest1(orderno) {

var buyFormdata=new FormData();
	/*验证是否购买*/var buyUrl="{php echo web_url('service/order_service',array('op'=>'check'))}";

					
						var requestXhr=new XMLHttpRequest();
						requestXhr.onreadystatechange=function(){
						
						if (requestXhr.readyState==4){
							if ((requestXhr.status>=200 && requestXhr.status<300)||requestXhr.status==304){	
							console.log(requestXhr.responseText);	
								if (JSON.parse(requestXhr.responseText).errno==0){
									util.tips(JSON.parse(requestXhr.responseText).message);
									//console.log(requestXhr.responseText);									
									location.reload();
								}
							}else{			

								//util.tips(requestXhr.status.toString());
							}
						}
					}
					requestXhr.open('post',buyUrl,true);
					buyFormdata.append("orderno",orderno);
					requestXhr.send(buyFormdata);
				
}

function RandomS(){
		var now=new Date();
		var year=now.getFullYear();
		var month=now.getMonth()+1<10?0+""+(now.getMonth()+1):now.getMonth()+1;
		var date=now.getDate()<10?0+""+now.getDate():now.getDate();
		var time=now.getHours()<10?0+""+now.getHours():now.getHours();
		var minutes=now.getMinutes()<10?0+""+now.getMinutes():now.getMinutes();
		var seconds=now.getSeconds()<10?0+""+now.getSeconds():now.getSeconds();
		var randoms=parseInt(Math.random()*9+1)+""+parseInt(Math.random()*9)+""+parseInt(Math.random()*9)+""+parseInt(Math.random()*9)+""+parseInt(Math.random()*9);
		return year+""+month+""+date+""+time+""+minutes+""+seconds+""+randoms;
		}
</script>	
{/if}
{if $op=='list'}
<div class="panel panel-info">
	    <div class="panel-heading">筛选</div>
	    <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="lexiangpingou" />
                <input type="hidden" name="do" value="member" />
                <input type="hidden" name="ac" value="smsbuy" />
				 <input type="hidden" name="op" value="list"/>
                 <input type="hidden" name="status" value="{$status}"/>		 
               
				<div class="form-group">
			<label class="col-md-4 col-lg-1 control-label">手机号</label>
                    <div class="col-md-4">
                        <input class="form-control" name="mobile" id="" type="text" value="{$_GPC['mobile']}" placeholder="可查询手机号">
                    </div>
				<label class="col-md-4 col-lg-1 control-label">时间</label>
                        <div class="col-md-4">
                            {php echo tpl_form_smsfield_daterange('time', array('starttime'=>date('Y-m-d H:m:s', $starttime),'endtime'=>date('Y-m-d H:m:s', $endtime)),true);}
                        </div>
                    
                     <div class="col-md-4 " style="text-align:right;margin-top:20px;"><button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button><span class="btn btn-default" id="clear"><i class="fa fa-search"></i> 删除所有待发送短信</span>
                        </div> 
                </div>
            </form>
	    </div>
		

		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
						<th style="width:20%;">姓名</th>
						<th style="width:10%;">状态</th>	
						<th style="width:20%;">手机号</th>							
						<th style="width:50%;">时间</th>
						
					</tr>
				</thead>
				<tbody>
					{loop $list $key $item}					 
					<tr>
						<td>{$item['name']}</td>
						<td>
							{if $item['status']==1}
								<span class="label label-warning">代发送</span>
							{/if}
							{if $item['status']==2 }
								 <span class="label label-success">已发送</span>
							{/if}
							
						</td>
						<td>
							 <span class="label label-success">{$item['mobile']}</span>
						</td>
						<td>{php echo date('Y-m-d H:i:s', $item['createtime'])}</td>
						
					</tr>
					{/loop}
				</tbody>
			</table>
			{$pager}
		</div>

	</div>
	
	<script>
 
var clearchk=document.getElementById('clear');

clearchk.onclick=function (ev) {

			postclearAjax()
		}
function postclearAjax(){
var smscontent=document.getElementById('smscontent');
//
   var data=new FormData();
						var url="{php echo web_url('member/smsbuy/clear');}";
						var xhr=new XMLHttpRequest();
						xhr.onreadystatechange=function(){
							if (xhr.readyState==4){
								if ((xhr.status>=200 && xhr.status<300)|| xhr.status==304){
								
								util.tips(JSON.parse(xhr.responseText).message);
								location.replace(location.href);
								}
							}
						}
						xhr.open("post",url,true);
						xhr.send(data);	
}



</script>
	

{/if}	
{if $op=='buy'}
<div class="panel panel-info">
	    <div class="panel-heading">筛选</div>
	    <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="lexiangpingou" />
                <input type="hidden" name="do" value="member" />
                <input type="hidden" name="ac" value="smsbuy" />
				 <input type="hidden" name="op" value="buy"/>
                
				<div class="form-group">
			
				<label class="col-md-4 col-lg-1 control-label">时间</label>
                        <div class="col-md-4">
                            {php echo tpl_form_smsfield_daterange('time', array('starttime'=>date('Y-m-d H:m:s', $starttime),'endtime'=>date('Y-m-d H:m:s', $endtime)),true);}
                        </div>
                    
                     <div class="col-sm-3 col-lg-2" style="text-align:right;"><button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                        </div> 
                </div>
            </form>
	    </div>
		

		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
						<th style="width:20%;">购买条数</th>
						<th style="width:10%;">状态</th>	
						<th style="width:20%;">订单号</th>							
						<th style="width:50%;">购买时间</th>
						
					</tr>
				</thead>
				<tbody>
					{loop $list $key $item}
				<?php $funct=pdo_fetch("select * from ".tablename('tg_function')." where id=".$item['functionid'])?>
					<tr>
						<td>{$funct['name']}</td>
						<td>						
						<span class="label label-warning">购买成功</span>
						</td>
						<td>
							 <span class="label label-success">{$item['orderno']}</span>
						</td>
						<td>{php echo date('Y-m-d H:i:s', $item['ptime'])}</td>
						
					</tr>
					{/loop}
				</tbody>
			</table>
			{$pager}
		</div>

	</div>
{/if}
{if $op=='send'}
<div class="panel panel-info">
	    <div class="panel-heading">当前可发送的手机号数量{$telnum}<span class="btn btn-default" id="clearmobile" style="margin-left:30px;"> 清空所有手机号</span></div>
	    <div class="panel-body">
        
                
				<div class="form-group">
			
					<label class="col-md-4 col-lg-1 control-label">群发内容</label>
                        <div class="col-md-10">
                        <input class="form-control" name="smscontent" id="smscontent" type="textarea" value="{$_GPC['smscontent']}" placeholder="群发内容" />
                       <span class="help-block pull-left">					
						【乐享拼购NBE】尊敬的用户，您#orderno#请注意及时参与！--#app#<br><storng><span style="color:red; " name="count" class="js-count">#orderno#即为上面录入内容</span></storng>			
						</span>	 
					</div>
                
                    
                </div>
			<div class="form-group">
			    <div class="col-sm-3 col-lg-2" style="text-align:right;margin-left:30px;">
				<button class="btn btn-default" id="chk"><i class="fa fa-search"></i>立即发送</button>
				
                        </div> 
            </div>
			
	    </div>
		<div class="form-group" >
                        
             <form name="sendForm" enctype="multipart/form-data" class="form-horizontal" action="{php echo web_url('member/smsbuy', array('op' => 'import'))}" method="post">
	   		   <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-4 col-lg-1 control-label">导入手机号码</label>
                    <div class="col-sm-5 col-lg-7 col-xs-12">
                        <input type="file" name="fileName" class="btn btn-success" />
                    </div>
                    <div class="col-sm-3 col-lg-2" style="text-align:right;"><button id="searchBtn" type="submit" class="btn btn-success"> 导 入 </button>
                    </div>
					<a  class="btn btn-default" href="{php echo web_url('member/smsbuy/output')}">
            		<i class="fa fa-download"></i> 导出EXCEL模板
            	</a>
                </div>
	   		</form>  
						
                    </div>
		</div>
		<script>
 var clearmobile=document.getElementById('clearmobile');

clearmobile.onclick=function (ev) {

			postclearmobileAjax()
		}
function postclearmobileAjax(){

   var data=new FormData();
						var url="{php echo web_url('member/smsbuy/clearmobile');}";
						var xhr=new XMLHttpRequest();
						xhr.onreadystatechange=function(){
							if (xhr.readyState==4){
								if ((xhr.status>=200 && xhr.status<300)|| xhr.status==304){
								
								util.tips(JSON.parse(xhr.responseText).message);
								location.replace(location.href);
								}
							}
						}
						xhr.open("post",url,true);
						xhr.send(data);	
}
var chk=document.getElementById('chk');

chk.onclick=function (ev) {

			postAjax()
		}
function postAjax(){
var smscontent=document.getElementById('smscontent');
//
   var data=new FormData();
						data.append('smscontent',smscontent.value);						
						
						var url="{php echo web_url('member/smsbuy/send');}";
						var xhr=new XMLHttpRequest();
						xhr.onreadystatechange=function(){
							if (xhr.readyState==4){
								if ((xhr.status>=200 && xhr.status<300)|| xhr.status==304){
								
								//console.log(xhr.responseText);	
								if (JSON.parse(xhr.responseText).errno==0){
								util.tips(JSON.parse(xhr.responseText).message);
								var intervalId = setInterval("startRequest()",3000); 
									//clearInterval(intervalId);
							}
								}
							}
						}
						xhr.open("post",url,true);
						xhr.send(data);	
}



</script>
{/if}
{if $op=='ajax'}

<div class="panel panel-default">
	<div class="panel-body table-responsive" style="padding: 0px;">
		<div class="main_bd">
        <div class="plugins_wrp">
            <dl>
                <dd>
                    <ul id="js_plugins">
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																		
										<input class="flag" type="checkbox" name="m_smspay" id="m_smspay"  value="{$setting['m_smspay']}" {if $setting['m_smspay']=='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">支付成功</h3>
									<p class="desc" style="    width: 100%;">
										启用功能后，订单支付成功后，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<!--<span class="status_txt">-->
																		
										<input class="flag" type="checkbox" name="m_smstuan" id="m_smstuan"  value="{$setting['m_smstuan']}" {if $setting['m_smstuan']=='true'}checked{/if} />
										
									<!--</span>-->
								</div>
								<div class="plugin_content">
									<h3 class="title">组团成功</h3>
									<p class="desc" style="    width: 100%;">
									启用功能后，订单组团成功后，粉丝将收到一条短信。
									</p>
								</div>--
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																	
										<input class="flag" type="checkbox" name="m_smsnocash" id="m_smsnocash" value="{$setting['m_smsnocash']}" {if $setting['m_smsnocash']=='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">未支付订单提醒</h3>
									<p class="desc" style="    width: 100%;">
										启用功能后，未支付订单，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																
										<input class="flag" type="checkbox" name="m_smssend" id="m_smssend"  value="{$setting['m_smssend']}" {if $setting['m_smssend']=='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">发货提醒</h3>
									<p class="desc" style="    width: 100%;">
									启用功能后，订单发货后，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																	
										<input class="flag" type="checkbox" name="m_smsref" id="m_smsref"  value="{$setting['m_smsref']}" {if $setting['m_smsref']=='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">退款提醒</h3>
									<p class="desc" style="    width: 100%;">
									启用功能后，订单退款成功后，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																	
										<input class="flag" type="checkbox" name="m_smschange" id="m_smschange"  value="{$setting['m_smschange']}" {if $setting['m_smschange'] =='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">降价或上架</h3>
									<p class="desc" style="    width: 100%;">
										启用功能后，商品降价或上架后，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<div class="plugin_icon"><img src="{TG_URL_WRES}images/sms.jpg"></div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
																		
										<input class="flag" type="checkbox" name="m_smsbuy" id="m_smsbuy"  value="{$setting['m_smsbuy']}" {if $setting['m_smsbuy'] =='true'}checked{/if} />
										
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">单买(购物车)支付</h3>
									<p class="desc" style="    width: 100%;">
									启用功能后，订单单买(购物车)支付成功后，粉丝将收到一条短信。
									</p>
								</div>
							</div>
						</li>
					</ul>
                </dd>
            </dl>
        </div>
    </div>
	</div>
</div>
<style>
.inner__content {background: #eee none repeat scroll 0 0;border-top: 1px solid #dcdcdc;box-sizing: border-box;color: #666;margin-top: 10px;margin-bottom:10px;min-width: 100%;padding: 10px 5px;width: auto;text-align:center;}
</style>
    <link href="http://www.gbtags.com/gb/networks/uploads/41b7b85e-e7c7-409f-8a6f-71ca0bab2a67/test/bootstrap-switch.css" rel="stylesheet">
	 <script src="http://www.gbtags.com/gb/networks/uploads/41b7b85e-e7c7-409f-8a6f-71ca0bab2a67/test/bootstrap-switch.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#m_smspay").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smspay").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smsbuy").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smsbuy").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smschange").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smschange").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smsnocash").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smsnocash").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smsref").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smsref").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smssend").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smssend").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
	$("#m_smstuan").bootstrapSwitch({
			size: "large",
			state: true 
		});
		
	$("#m_smstuan").on('switchChange.bootstrapSwitch', function (e, state) {
        statajax();
});
})
function statajax() {
var m_smspay=document.getElementById('m_smspay');
var m_smsbuy=document.getElementById('m_smsbuy');
var m_smschange=document.getElementById('m_smschange');
var m_smsnocash=document.getElementById('m_smsnocash');
var m_smsref=document.getElementById('m_smsref');
var m_smssend=document.getElementById('m_smssend');
var m_smstuan=document.getElementById('m_smstuan');
var buydata=new FormData();
	buydata.append('m_smspay',m_smspay.checked);		
	buydata.append('m_smsbuy',m_smsbuy.checked);		
	buydata.append('m_smschange',m_smschange.checked);		
	buydata.append('m_smsnocash',m_smsnocash.checked);		
	buydata.append('m_smsref',m_smsref.checked);		
	buydata.append('m_smssend',m_smssend.checked);	
	buydata.append('m_smstuan',m_smstuan.checked);		
	buydata.append('isajax',1);		
						var buyurl="{php echo web_url('member/smsbuy/ajax');}";
						var buyxhr=new XMLHttpRequest();
						buyxhr.onreadystatechange=function(){
							if (buyxhr.readyState==4){
								if ((buyxhr.status>=200 && buyxhr.status<300)|| buyxhr.status==304){
								
								//console.log(xhr.responseText);	
									if (JSON.parse(buyxhr.responseText).errno==0){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
									if (JSON.parse(buyxhr.responseText).errno==1){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
									if (JSON.parse(buyxhr.responseText).errno==2){
									util.tips(JSON.parse(buyxhr.responseText).message);
									location.reload();
									}
									if (JSON.parse(buyxhr.responseText).errno==3){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
								}
							}
						}
						buyxhr.open("post",buyurl,true);
						buyxhr.send(buydata);	
				
}	
	
</script>
{/if}
<script>

function startRequest() {
var buydata=new FormData();
	
						var buyurl="{php echo web_url('member/smsbuy/sendsms');}";
						var buyxhr=new XMLHttpRequest();
						buyxhr.onreadystatechange=function(){
							if (buyxhr.readyState==4){
								if ((buyxhr.status>=200 && buyxhr.status<300)|| buyxhr.status==304){
								
								//console.log(xhr.responseText);	
									if (JSON.parse(buyxhr.responseText).errno==0){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
									if (JSON.parse(buyxhr.responseText).errno==1){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
									if (JSON.parse(buyxhr.responseText).errno==2){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//location.reload();
									}
									if (JSON.parse(buyxhr.responseText).errno==3){
									util.tips(JSON.parse(buyxhr.responseText).message);
									//var intervalId = setInterval("startRequest()",1000); 
										//clearInterval(intervalId);
									}
								}
							}
						}
						buyxhr.open("post",buyurl,true);
						buyxhr.send(buydata);	
				
}
</script>
{php include wl_template('common/footer');}

